<?php
	/*
	* 我的财务
	*/
	class finance{
		
		public $t;
		public $PageSize=10;
		
		
		/*
		* 充值记录
		*/
		function getRechargeList(){
			global $db;
			$begDate = '';
			if (isset($_GET['begDate'])) {
			  $begDate = $_GET['begDate'];
			};
			$endDate = '';
			if (isset($_GET['endDate'])) {
			  $endDate = $_GET['endDate'];
			};
			// $endDate=empty($_GET['endDate']) ? 0 : $_GET('endDate');
			// $begDate = $_GET['begDate'];
			// $endDate = $_GET['endDate'];
			$where="1=1 ";
			if($begDate){
				$where.=" and createdate >".strtotime($begDate);
			}
			if($endDate){
				$where.=" and createdate<".strtotime($endDate);
			}
			$sql="select * from log_recharge where ".$where." and admin_action=1 and mem_id=".$_SESSION['login']['userId']." order by createdate desc";
			$total=$db->QueryCount($sql);
			$this->t=array('total'=>$total,'perpage'=>$this->PageSize,'style'=>'a2');
			$tmpPage=empty($_GET['PageNum']) ? 0 : intval($_GET['PageNum']);
			$tmpPageSize=$tmpPage==0 ? 0 : ($tmpPage-1)*$this->PageSize;
			$sql .= ' limit '.$tmpPageSize.','.$this->PageSize ;
			$rs = $db->GetAllSql($sql);
			return $rs;
			
		}
		/*
		* 扣款记录
		*/
		function getConsumerList(){
			global $db;
            $begDate = '';
			if (isset($_GET['begDate'])) {
			  $begDate = $_GET['begDate'];
			};
			$endDate = '';
			if (isset($_GET['endDate'])) {
			  $endDate = $_GET['endDate'];
			};			$where="1=1 ";
			if($begDate){
				$where.=" and createdate >".strtotime($begDate);
			}
			if($endDate){
				$where.=" and createdate<".strtotime($endDate);
			}
			$sql="select * from log_recharge where ".$where." and admin_action=0 and mem_id=".$_SESSION['login']['userId']." order by createdate desc";
			$total=$db->QueryCount($sql);
			$this->t=array('total'=>$total,'perpage'=>$this->PageSize,'style'=>'a2');
			$tmpPage=empty($_GET['PageNum']) ? 0 : intval($_GET['PageNum']);
			$tmpPageSize=$tmpPage==0 ? 0 : ($tmpPage-1)*$this->PageSize;
			$sql .= ' limit '.$tmpPageSize.','.$this->PageSize ;
			$rs = $db->GetAllSql($sql);
			return $rs;	
		}
		/*订单报表*/
		function getOrdersList(){
			global $db;
			$begDate=$_GET['begDate'];
			$endDate=$_GET['endDate'];
			$where="1=1 ";
			if($begDate){
				$where.=" and Fin_createtime > ".strtotime($begDate);
			}
			if($endDate){
				$where.=" and Fin_createtime < ".strtotime($endDate);
			}
			$sql="select * from fin_log where ".$where." and Fin_cst_id=".$_SESSION['login']['userId']." order by Fin_createtime desc";
			$total=$db->QueryCount($sql);
			$this->t=array('total'=>$total,'perpage'=>$this->PageSize,'style'=>'a2');
			$tmpPage=$_GET['PageNum']!="" ? intval($_GET['PageNum']):0;
			$tmpPageSize=$tmpPage==0 ? 0 : ($tmpPage-1)*$this->PageSize;
			$sql .= ' limit '.$tmpPageSize.','.$this->PageSize ;
			//return $sql;
			$rs = $db->GetAllSql($sql);
			return $rs;
		}
		
		/*订单总额情况*/
		function getOrderYE(){
			global $db;
			$sql="select count(*) as num,sum(Tord_num) as subNum,sum(Tord_price2) as xsPrice from ticket_order where Tord_status=5 and Tord_cst_id=".$_SESSION['login']['userId'];
			$rs=$db->GetOneSql($sql);
			return $rs;
		}
		
		/*计算利润*/
		function getProfit(){
			global $db;
			$sql="select * from ticket_order where Tord_status=5 and Tord_cst_id=".$_SESSION['login']['userId'];
			$rs=$db->GetAllSql($sql);
			$profit=0;
			foreach($rs as $v){
				$profit+=($v['Tord_price2']-$v['Tord_price3'])*$v['Tord_num'];
			}
			return $profit;
		}
		
		/*
		* 分页
		*/
		function page(){
			return new page($this->t);	
		}
		
		
		
	}
?>